package com.lwj.liwanjia.view.activity.personal;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.utils.SpUtils;

/**
 * 系统设置
 * Created by 001 on 2017/9/10.
 */

public class XiTongSheZhiActivity extends BaseActivity implements View.OnClickListener {

    private TextView tv_back;
    private TextView tv_title;
    private ImageView iv_shengYin;//声音开关
    private ImageView iv_zhengDong;//震动开关
    private boolean isShengYin = true;//声音 切换 控制字段
    private boolean isZhengDong = true;//震动 切换 控制字段

    @Override
    protected void initView() {

        tv_back = (TextView) findViewById(R.id.tv_left);
        tv_title = (TextView) findViewById(R.id.tv_title);
        iv_shengYin = (ImageView) findViewById(R.id.iv_shengYin);
        iv_zhengDong = (ImageView) findViewById(R.id.iv_zhengDong);

        tv_back.setVisibility(View.VISIBLE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("设置");

        tv_back.setOnClickListener(this);
        iv_shengYin.setOnClickListener(this);
        iv_zhengDong.setOnClickListener(this);

        //初始化开关
        initKaiGuan();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_xi_tong_she_zhi;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.tv_left:
                finish();
                break;
            //声音
            case R.id.iv_shengYin:

                if (isShengYin) {
                    iv_shengYin.setImageResource(R.mipmap.off_1);
                }else {
                    iv_shengYin.setImageResource(R.mipmap.on_1);
                }

                isShengYin = !isShengYin;

                SpUtils.putBoolean(XiTongSheZhiActivity.this,"isShengYin",isShengYin);

                break;
            //震动:
            case R.id.iv_zhengDong:

                if (isZhengDong) {
                    iv_zhengDong.setImageResource(R.mipmap.off_1);
                }else {
                    iv_zhengDong.setImageResource(R.mipmap.on_1);
                }

                isZhengDong = !isZhengDong;

                SpUtils.putBoolean(XiTongSheZhiActivity.this,"isZhengDong",isZhengDong);

                break;
        }
    }

    //初始化开关
    private void initKaiGuan() {

        boolean isShengYin = SpUtils.getBoolean(this, "isShengYin", false);
        boolean isZhengDong = SpUtils.getBoolean(this, "isZhengDong", false);

        if (isShengYin) {
            iv_shengYin.setImageResource(R.mipmap.on_1);
        }else {
            iv_shengYin.setImageResource(R.mipmap.off_1);
        }

        if (isZhengDong) {
            iv_zhengDong.setImageResource(R.mipmap.on_1);
        }else {
            iv_zhengDong.setImageResource(R.mipmap.off_1);
        }


    }
}
